/*
 * test.c
 *
 *  Created on: Jul 8, 2009
 *      Author: jacky
 */
#include <stdio.h>
#include <stdlib.h>
//#define CUR_CTL(x) test_##x

#define NA(array) (sizeof(array)/sizeof(array[0]))

#define DECLARE_ACTIONS(args...) \
	enum { CUR_CTL(reserve), \
	args, \
	CUR_CTL(ACTIONEOF)}; \
	extern Action CUR_CTL(actions)[CUR_CTL(ACTIONEOF)];\
	extern int CUR_CTL(actionLength);

#define INIT_ACTION(actname, actionfun) \
	[CUR_CTL(actname)]={.name = #actname,.action = actionfun}

#define DEFINE_ACTIONS(arg...)  \
	Action CUR_CTL(actions)[] = { arg }; \
	int CUR_CTL(actionLength)= NA(CUR_CTL(actions))

#define DEFINE_ACTION_FUNC(actionfun) static ActionStatus actionfun(HttpRequest *request,HttpResponse *response)
typedef enum
{
	ActionOK = 0, ActionFAIL,
} ActionStatus;
typedef struct HttpResponse HttpResponse;
typedef struct HttpRequest HttpRequest;
typedef struct Controller Controller;
typedef struct Action Action;
typedef ActionStatus (*ActionFUN)(HttpRequest*, HttpResponse*);
typedef void (*ViewFUN)(HttpRequest*, HttpResponse*);
struct Action
{
	char *name;
	ActionFUN action;
};

//---------------------------------------------------
DECLARE_ACTIONS(CUR_CTL(index),CUR_CTL(info),CUR_CTL(cgiEnv),CUR_CTL(upload))
;

DEFINE_ACTION_FUNC(upload_action)
{
	ActionStatus result;
	return result;
}

DEFINE_ACTIONS(INIT_ACTION(upload,upload_action))
;

int main(int argc, char **argv)
{
	int result = 0;
	char ctrl[1024];
	char action[1024];
	sscanf("do=/test/f1eee", "do=/%[^/]/%[^/]", ctrl, action);
	printf("ctrl=%d action=%d\n", atoi(ctrl), atoi(action));
	//	ACTION(aaa,bbb);
	return result;
}
